import API from '../../api/api.js'
const FORMAT = require('../../api/util.js')
const app = getApp()
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    screenHeight: Number,
    dataList: Array
  },

  /**
   * 组件的初始数据
   */
  data: {
    CustomBar: app.globalData.CustomBar,
    typeList: [{
        type: "期待鼓励"
      },
      {
        type: "期待支持"
      },
      {
        type: "迷茫抉择"
      },
      {
        type: "两性感情"
      },
      {
        type: "真实故事"
      },
      {
        type: "办公秩事"
      }
    ]
  },

  ready: function () {
    let animation = wx.createAnimation({
      duration: 800,
      timingFunction: 'ease'
    })
    let animation_top = wx.createAnimation({
      duration: 800,
      timingFunction: 'ease'
    })
    let next = true
    // 连续动画
    setInterval(function () {
      if (next) {
        animation.translateX(6).step()
        animation_top.translateY(6).step()
        next = !next;
      } else {
        animation.translateX(0).step()
        animation_top.translateY(0).step()
        next = !next;
      }
      this.setData({
        ani: animation.export(),
        ani_top: animation_top.export()
      })
    }.bind(this), 900)

  },

  /**
   * 组件的方法列表
   */
  methods: {

    checkLogin:function(e){
      let isLogin = wx.getStorageSync('isLogin')
      if(isLogin){
        return true
      }else{
        return false
      }
    },
    //切换数据类型
    tuChenFunc: function (e) {
      if(!this.checkLogin()){
        wx.showToast({
          title: '您还没有登录，请到【我的】登录查看内容。',
          icon:"none"
        })
        return
      }
      let that = this
      that.setData({
        tuchen: e.currentTarget.dataset.target
      })
    },
    //隐藏左侧弹出框
    hideTuChenLayerModal(e) {
      this.setData({
        tuchen: null
      })
    },
    //点击目标按钮方法
    muBiaoFunc: function (e) {
      let that = this
      that.setData({
        mubiao: "scale-down"
      })
      setTimeout(function () {
        that.setData({
          mubiao: ''
        })
      }, 1000)
      if(!this.checkLogin()){
        wx.showToast({
          title: '您还没有登录，请到【我的】登录查看内容。',
          icon:"none"
        })
        return
      }
      wx.navigateTo({
        url: "/pages/wodemubiao/wodemubiao"
      })

    },

    //点击话题按钮方法
    huaTiFunc: function (e) {
      let that = this
      that.setData({
        huati: "scale-down"
      })
      setTimeout(function () {
        that.setData({
          huati: ''
        })
      }, 1000)
      if(!this.checkLogin()){
        wx.showToast({
          title: '您还没有登录，请到【我的】登录查看内容。',
          icon:"none"
        })
        return
      }
      wx.navigateTo({
        url: "/pages/wentieveryday/wentieveryday"
      })
    },
    //点击飘浮信封方法
    dianJiXingFeng: function (e) {
      let item = e.currentTarget.dataset.value
      if(!this.checkLogin()){
        wx.showToast({
          title: '您还没有登录，请到【我的】登录查看内容。',
          icon:"none"
        })
        return
      }
      wx.navigateTo({
        url: "/pages/wenzhangdetail/wenzhangdetail?id=" + item._id
      })
    },

    //点击弹出框类型文字方法
    leiXingFunc: function (e) {
      let type = e.currentTarget.dataset.value.type
      API.getTypeArticle('wenzhangbiao', type, 5).then(res => {
        this.setData({
          dataList: res,
          tuchen: null
        })
      })
    },

    //点击限时心情方法
    xianShiFunc: function (e) {
      let that = this
      that.setData({
        xianShi: "scale-down"
      })
      setTimeout(function () {
        that.setData({
          xianShi: ''
        })
      }, 1000)
      if(!this.checkLogin()){
        wx.showToast({
          title: '您还没有登录，请到【我的】登录查看内容。',
          icon:"none"
        })
        return
      }
      let currTime = FORMAT.formatDay(Math.floor(new Date().getTime() / 1000))
      API.getXianShiArticle("wenzhangbiao", currTime, 5).then(res => {
        this.setData({
          dataList: res
        })
      })
    },
    
    toHelpInfo:function(e){
      API.getDataById("wenzhangbiao", '6518b7395f5dcc800169788d6823ab12').then(res => {
        let data = {
          neiRong: res[0].neiRong,
          type: res[0].tiMu
        }
        wx.setStorageSync('currContent', data)
        wx.navigateTo({
          url: "/pages/conentdisplay/conentdisplay",
        })
      })
    }
  }
})